package cn.ikun.dcx;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppReflect {
    public static void main(String[] args) throws Exception{
        Class<?> A = Class.forName("cn.ikun.dcx.Animal");
        Object o = A.newInstance();
        Field[] fields = A.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            field.setAccessible(true);
            Class<?> type = field.getType();
            if (type.toString().endsWith("String")) {
                field.set(o, "ddd");
            } else if (type.toString().endsWith("Integer")) {
                field.set(o, 19);
            } else if (type.toString().endsWith("Double")) {
                field.set(o, 5.5);
            }
        }
        Method say =A.getDeclaredMethod("say");
        say.invoke(o);
    }
}
